package com.leo.ktvplayer.localcookie;

import android.preference.PreferenceManager;

import com.alipay.api.domain.PricingVO;
import com.leo.ktvplayer.base.App;
import com.leo.ktvplayer.domain.bean.Setting;
import com.leo.ktvplayer.domain.bean.User;
import com.leo.ktvplayer.util.JsonUtil;

/**
 *
 */
public class LocalUtils {
    public static User getUser(){
        String result = PreferenceManager.getDefaultSharedPreferences(App.getInstance()).getString(TAG_USER,null);
        if(result == null) {
            return new User();
        }
        return JsonUtil.jsonStrToObj(User.class,result);
    }
    public static void saveUser(User user) {
        if (user != null) {
            String result =  JsonUtil.objToJsonStr(user);
            PreferenceManager.getDefaultSharedPreferences(App.getInstance()).edit().putString(TAG_USER,result).commit();
        }
    }

    public static void saveSetting(Setting setting){
        if (setting != null) {
            String result = JsonUtil.objToJsonStr(setting);
            PreferenceManager.getDefaultSharedPreferences(App.getInstance()).edit().putString(TAG_SETTING , result).commit();
        }
    }

    public static Setting getSetting(){
        String result = PreferenceManager.getDefaultSharedPreferences(App.getInstance()).getString(TAG_SETTING,null);
        if (result != null){
            return JsonUtil.jsonStrToObj(Setting.class,result);
        } else {
            return new Setting();
        }
    }

    private static String TAG_USER = "com.leo.ktvplayer.TAG_USER";
    private static String TAG_SETTING = "com.leo.ktvplayer.TAG_SETTING";
}
